<!-- 修改密码页面 【弹出层】 -->
<link rel="stylesheet" href="{_ADMIN_STATIC_}/buttons/button.css">
<link rel="stylesheet" href="{_ADMIN_STATIC_}/lib/bootstrap/css/bootstrap.min.css">
<style>
    #edit_password {
        position: relative;
        width: 100%;
        height: 100%;
        text-align: center;
    }

    #up {
        position: absolute;
        width: 100%;
        height: 120px;
        line-height: 120px;
        text-align: center;
    }

    #down {
        position: absolute;
        bottom: 10;
        width: 100%;
        height: 40px;
    }
</style>

<div id="edit_password">
    <div id="up">
        <table class="table">
            <tr>
                <td>原 密 码</td>
                <td><input type="password" id="old_password" placeholder="请输入原密码"></td>
                <td style="color:#F00;">*必填</td>
            </tr>
            <tr>
                <td>修改密码</td>
                <td><input type="password" id="new_password" placeholder="请输入要修改的密码"></td>
                <td style="color:#F00;">*必填</td>
            </tr>
            <tr>
                <td>确认密码</td>
                <td><input type="password" id="confirm_password" placeholder="请确认密码"></td>
                <td style="color:#F00;">*必填</td>
            </tr>
            </tbody>
          </table>
    </div>

    <div id="down">
        <button class="button button-raised button-primary button-pill" onclick="save()">修改</button>
        <button class="button button-raised button-primary button-pill" onclick="back()">返回</button>
    </div>

</div>

<script src="{_ADMIN_STATIC_}/lib/jquery/jquery.js"></script>
<script src="{_ADMIN_STATIC_}/lib/layer/layer.js"></script>
<script>

    // 修改密码按钮
    function save() {

        var old_password = $('#old_password').val().trim();
        var new_password = $('#new_password').val().trim();
        var confirm_password = $('#confirm_password').val().trim();

        if(new_password.length <6)
        {
            return layer.msg('密码长度不少于6位', { icon: 4, time: 900 });
        }
        if(new_password != confirm_password){
            return layer.msg('两次密码不一致', { icon: 2, time: 900 });
        }

        $.ajax({
            url: "{:url('admin/edit_password')}",
            data: {
                'old_password': old_password,
                'new_password': new_password,
                'confirm_password': confirm_password
            },
            type: "POST",
            dataType: "JSON",
            success: function (res) {
                // 返回结果处理
                if (res.code == 0) {
                    layer.msg(res.msg, { icon: 1, time: 900 });
                } else {
                    layer.msg(res.msg, { icon: 2, time: 900 });
                }
            }
        });
    }

    // 返回按钮
    function back() {
        // 获取到父级容器
        var index = parent.layer.getFrameIndex(window.name);
        // 关闭父级容器
        parent.layer.close(index);
    }

</script>